package com.zzyl.nursing.mapper;

import java.time.LocalDateTime;
import java.util.List;

import com.zzyl.nursing.domain.FamilyMember;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzyl.nursing.vo.FamilyMemberElderRelationVO;
import com.zzyl.nursing.vo.FamilyMemberElderVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.DeleteMapping;

/**
 * 老人家属Mapper接口
 *
 * @author ruoyi
 * @date 2025-04-26
 */
@Mapper
public interface FamilyMemberMapper extends BaseMapper<FamilyMember> {

    @Delete("delete from family_member_elder where elder_id = #{id}")
    void deleteFamilyElderMemberById(Long id);

    /**
     * 查询老人家属
     *
     * @param id 老人家属主键
     * @return 老人家属
     */
    public FamilyMember selectFamilyMemberById(Long id);

    /**
     * 查询老人家属列表
     *
     * @param familyMember 老人家属
     * @return 老人家属集合
     */
    public List<FamilyMember> selectFamilyMemberList(FamilyMember familyMember);

    /**
     * 新增老人家属
     *
     * @param familyMember 老人家属
     * @return 结果
     */
    public int insertFamilyMember(FamilyMember familyMember);

    /**
     * 修改老人家属
     *
     * @param familyMember 老人家属
     * @return 结果
     */
    public int updateFamilyMember(FamilyMember familyMember);

    /**
     * 删除老人家属
     *
     * @param id 老人家属主键
     * @return 结果
     */
    public int deleteFamilyMemberById(Long id);

    /**
     * 批量删除老人家属
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteFamilyMemberByIds(Long[] ids);

    /**
     * 新增老人和家属关系
     * @param userId
     * @param elderId
     * @param createBy
     * @param updateBy
     * @param createTime
     * @param updateTime
     * @param remark
     */
    void addElderAndMember(@Param("userId") Long userId, @Param("elderId") Long elderId, @Param("createBy") Long createBy, @Param("updateBy") Long updateBy, @Param("createTime") LocalDateTime createTime, @Param("updateTime") LocalDateTime updateTime, @Param("remark") String remark);

    /**
     * 获取当前登录用户的所有家属-老人关联信息
     * @param userId
     * @return
     */
    List<FamilyMemberElderVo> getMyFamilyElder(Long userId);

    /**
     * 获取所有家属-老人关联信息
     * @return
     */
    List<FamilyMemberElderRelationVO> listByPage(Long userId);

    /**
     * 获取时间段内所有数据
     * @param iotId
     * @param functionId
     * @param nowTime
     * @param nextTime
     * @return
     */
    Double getTimeSlotsAvg(@Param("iotId") String iotId,@Param("functionId") String functionId,@Param("startTime") LocalDateTime nowTime,@Param("endTime") LocalDateTime nextTime);

    /**
     * 获取时间段内心率数据
     * @param iotId
     * @param heartRate
     * @param currentDay
     * @param nextDay
     * @return
     */
    Double getDailyHeartRateAvg(@Param("iotId") String iotId,@Param("functionId") String heartRate,@Param("startTime") LocalDateTime currentDay,@Param("endTime") LocalDateTime nextDay);

    @Select("select * from family_member_elder where family_member_id = #{userId} and elder_id = #{id}")
    FamilyMember selectFamilyMemberBingdingElder(@Param("userId") Long userId,@Param("id") Long id);
}
